/**
 * @file       EventQueue.h
 * @brief      For store the event object  temporarily
 * @author     Huabo Zheng
 * @date       Jan 20, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef EVENTQUEUE_H_
#define EVENTQUEUE_H_

#include "Object.h"
#include <queue>
#include "Mutex.h"

namespace NS_LCD_AFW
{
class IEvent;
/**
 *NS_LCD_AFW::CEventQueue
 */

/**
 *@class  CEventQueue
 *@brief  For store the event object  temporarily
 */
class CEventQueue: public NS_LCD_AFW::CObject
{
public:
	/**
	 *@brief Constructor
	 */
	CEventQueue();

	/**
	*@brief DeConstructor
	*/
	virtual ~CEventQueue();


	/**
	 *@brief  Add a pEvent object to the last of the  queue
	 *@details     Add a pEvent object to queue,and it is a thread-safe operation
	 *@param[in]  pEvent A pointer to a IEvent object
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note
	 *@attention
	 *@see peekEvent
	 *@see getEvent
	*/
	int addEvent(IEvent *pEvent);

	/**
	 *@brief  To check if there is event in the queue
	 *@details    To check if there is event in the queue,it is  thread-safe
	 *@param[out]  pEvent A pointer to a IEvent object
	 *@exception none
	 *@retval    bool
	 *@return    true if queue is not empty,and pEvent points to the first event object in the queue,otherwise return false and pEvent will be set to NULL
	 *@note
	 *@attention
	 *@see addEvent
	 *@see getEvent
	*/
	bool peekEvent(IEvent *&pEvent) const;

	/**
	 *@brief  Get Event From Queue
	 *@details    Get Event From Queue,it is  thread-safe
	 *@param[out]  pEvent A pointer to a IEvent object
	 *@exception none
	 *@retval    bool
	 *@return    true if queue is not empty,and pEvent points to the first event object in the queue,otherwise return false and pEvent will be set to NULL
	 *@note
	 *@attention  After return,the event at the front will be poped
	 *@see peekEvent
	 *@see addEvent
	*/
	bool getEvent(IEvent *&pEvent);

private:
	/**
	 *@typedef std::queue<IEvent *> IEventQueue
	 */
	typedef std::queue<IEvent *> IEventQueue;
	IEventQueue m_eventQueue;

private:
	static CMutex m_sMutex;

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CEventQueue);
};

/**
 *@class  CAppEventQueue
 *@brief  For store the application event object  temporarily
 */
class CAppEventQueue: public CEventQueue
{
};

/**
 *@class  CSysEventQueue
 *@brief  For store the system event object  temporarily
 */
class CSysEventQueue: public CEventQueue
{
};

/**
 *@def  AfwGetAppEventQueue()
 *@brief Get the Application queue object instance
 */
#define AfwGetAppEventQueue()         (&(CSafeSingleton<CAppEventQueue>::getInstance()))

/**
 *@def  AfwGetSysEventQueue()
 *@brief Get the system queue object instance
 */
#define AfwGetSysEventQueue()         (&(CSafeSingleton<CSysEventQueue>::getInstance()))
} /* namespace NS_LCD_AFW */
#endif /* EVENTQUEUE_H_ */
